import java.util.Iterator;
import java.util.Vector;


public class Packet {

	private byte type;
	private int fieldNumber;
	private int size;
	private Vector<Field> fields;

	public Packet(byte type)
	{
		this.type = type;
		this.fields = new Vector<Field>();
	}

	public void addField(Field f)
	{
		fields.add(f);
	}
	
	public void printToLog(Logger log)
	{
		String str = "<" + String.format("%x", type) + "|" + getStringType() + ">";
		Iterator<Field> itr = fields.iterator();
		
		while(itr.hasNext())
		{
			str = str + ";";
			Field f = itr.next();
			str = str + f.toString();
		}
		log.write(str);
	}

	public String getStringType()
	{
		switch (this.type)
		{
		case (byte) 0x00:
			return ("Keep Alive");
		case (byte) 0x01:
			return "Login request";
		case (byte) 0x02:
			return "Handshake";
		case (byte) 0x03:
			return "Chat message";
		case (byte) 0x04:
			return "Time Update";
		case (byte) 0x05:
			return "Entity Equipment";
		case (byte) 0x06:
			return "Spawn Position";
		case (byte) 0x07:
			return "Use Entity";
		case (byte) 0x08:
			return "Update Health";
		case (byte) 0x09:
			return "Respawn";
		case (byte) 0x0A:
			return "Player";
		case (byte) 0x0B:
			return "Player Position";
		case (byte) 0x0C:
			return "Player Look";
		case (byte) 0x0D:
			return "Player Position & Look";
		case (byte) 0x0E:
			return "Player Digging";
		case (byte) 0x0F:
			return "Player Block Placement";
		case (byte) 0x10:
			return "Held Item";
		case (byte) 0x11:
			return "Use Bed";
		case (byte) 0x12:
			return "Animation";
		case (byte) 0x13:
			return "Entity Action";
		case (byte) 0x14:
			return "Spawn Named Entity";
		case (byte) 0x15:
			return "Spawn Dropped Item";
		case (byte) 0x16:
			return "Collect Item";
		case (byte) 0x17:
			return "Spawn Object Vehicle";
		case (byte) 0x18:
			return "Spawn Mob";
		case (byte) 0x19:
			return "Spawn Painting";
		case (byte) 0x1A:
			return "Spawn Experience Orb";
		case (byte) 0x1C:
			return "Entity Velocity";
		case (byte) 0x1D:
			return "Destroy Entity";
		case (byte) 0x1E:
			return "Entity";
		case (byte) 0x1F:
			return "Entity Relative Move";
		case (byte) 0x20:
			return "Entity Look";
		case (byte) 0x21:
			return "Entity Look & Relative Move";
		case (byte) 0x22:
			return "Entity Teleport";
		case (byte) 0x23:
			return "Entity Head Look";
		case (byte) 0x26:
			return "Entity Status";
		case (byte) 0x27:
			return "Attach Entity";
		case (byte) 0x28:
			return "Entity Metadata";
		case (byte) 0x29:
			return "Entity Effect";
		case (byte) 0x2A:
			return "Remove Entity Effect";
		case (byte) 0x2B:
			return "Set Experience";
		case (byte) 0x32:
			return "Map Column Allocation";
		case (byte) 0x33:
			return "Map Chunks";
		case (byte) 0x34:
			return "Multi Block Change";
		case (byte) 0x35:
			return "Block Change";
		case (byte) 0x36:
			return "Block Action";
		case (byte) 0x3C:
			return "Explosion";
		case (byte) 0x3D:
			return "Sound/Particle Effect";
		case (byte) 0x46:
			return "Change Game State";
		case (byte) 0x47:
			return "Thunderbolt";
		case (byte) 0x64:
			return "Open Window";
		case (byte) 0x65:
			return "Close Window";
		case (byte) 0x66:
			return "Clock Window";
		case (byte) 0x67:
			return "Set Slot";
		case (byte) 0x68:
			return "Set Windo Items";
		case (byte) 0x69:
			return "Update Window Property";
		case (byte) 0x6A:
			return "Confirm Transaction";
		case (byte) 0x6B:
			return "Creative Inventory Action";
		case (byte) 0x6C:
			return "Enchant Item";
		case (byte) 0x82:
			return "Update Sign";
		case (byte) 0x83:
			return "Item Data";
		case (byte) 0x84:
			return "Update Tile Entity";
		case (byte) 0xC8:
			return "Increment Statistic";
		case (byte) 0xC9:
			return "Player List Item";
		case (byte) 0xCA:
			return "Player Abilities";
		case (byte) 0xFA:
			return "Plugin Message";
		case (byte) 0xFE:
			return "Server List Ping";
		case (byte) 0xFF:
			return "Disconnect/kick";
		}
		return "Unknown packet";

	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}
}
